package com;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class One
 */
@WebServlet("/one")
public class Demo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Demo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		List<String> data_title = new ArrayList<>();
		List<One> data_data = new ArrayList<>();
		One aOne = new One("aa", "aaa");
		One bOne = new One("bb", "bbb");
		data_data.add(aOne);
		data_data.add(bOne);
		
		data_title.add("A");
		data_title.add("B");
		
		String[][] two = new String[data_data.size()+1][data_title.size()];
		
		for(int i = 0;i<data_title.size();i++){
			two[0][i] = data_title.get(i).toString();
		}
		for(int i = 0;i<data_data.size();i++){
			two[i+1][0] = data_data.get(i).getA();
			two[i+1][1] = data_data.get(i).getB();
		}
		System.out.println(two.length);
		
		for(int i=0;i<two.length;i++){
			for(int j = 0;j<two[0].length;j++){
				System.out.print(two[i][j]+" ");
			}
			System.out.println();
		}

		ExportUitls.saveAndOut(two, "abc", request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
class One {
	public String a;
	public String b;

	public One(String a, String b) {
		super();
		this.a = a;
		this.b = b;
	}

	public String getA() {
		return a;
	}

	public void setA(String a) {
		this.a = a;
	}

	public String getB() {
		return b;
	}

	public void setB(String b) {
		this.b = b;
	}
}
